<!DOCTYPE html>
<!--
  Copyright 2016 Google Inc.

  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  THE SOFTWARE.
-->
<html>
  <head>
    <meta charset="utf-8">
    <title>Chips - Material Components Catalog</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="icon" type="image/png" href="/images/logo_components_color_2x_web_48dp.png">
    <link rel="stylesheet" href="/assets/chips.css">
    <script src="/ready.js"></script>
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto+Mono">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500">
    <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
  </head>
  <body class="mdc-typography">
    <header class="mdc-toolbar mdc-toolbar--fixed">
      <div class="mdc-toolbar__row">
        <section class="mdc-toolbar__section mdc-toolbar__section--align-start">
          <span class="catalog-back">
            <a href="/" class="mdc-toolbar__menu-icon"><i class="material-icons">&#xE5C4;</i></a>
          </span>
          <span class="mdc-toolbar__title catalog-title">Chips</span>
        </section>
      </div>
    </header>

    <main class="mdc-toolbar-fixed-adjust">
      <section class="hero">
        <div class="mdc-chip-set">
          <div class="demo-chip mdc-chip" tabindex="0">
            <div class="mdc-chip__text">Chip One</div>
          </div>
          <div class="demo-chip mdc-chip" tabindex="0">
            <div class="mdc-chip__text">Chip Two</div>
          </div>
          <div class="demo-chip mdc-chip" tabindex="0">
            <div class="mdc-chip__text">Chip Three</div>
          </div>
          <div class="demo-chip mdc-chip" tabindex="0">
            <div class="mdc-chip__text">Chip Four</div>
          </div>
        </div>
      </section>

      <section class="example">
        <div id="input-chip-icon-clones">
            <i class="input-leading-icon material-icons mdc-chip__icon mdc-chip__icon--leading">face</i>
            <i class="input-trailing-icon material-icons mdc-chip__icon mdc-chip__icon--trailing" tabindex="0" role="button">cancel</i>
        </div>
        <h2>Input Chips</h2>
        <input id="input-chip-set-input" placeholder="Chip text">
        <button id="input-chip-set-button" class="mdc-button mdc-button--dense">
          Add Input Chip
        </button>
        <button id="input-chip-set-delete-button" class="mdc-button mdc-button--dense">
          Delete Last Chip
        </button>
        <div id="input-chip-set" class="mdc-chip-set mdc-chip-set--input">
          <div class="demo-chip mdc-chip" tabindex="0">
            <i class="material-icons mdc-chip__icon mdc-chip__icon--leading">face</i>
            <div class="mdc-chip__text">Jane Smith</div>
            <i class="material-icons mdc-chip__icon mdc-chip__icon--trailing" tabindex="0" role="button">cancel</i>
          </div>
          <div class="demo-chip mdc-chip" tabindex="0">
            <i class="material-icons mdc-chip__icon mdc-chip__icon--leading">face</i>
            <div class="mdc-chip__text">John Doe</div>
            <i class="material-icons mdc-chip__icon mdc-chip__icon--trailing" tabindex="0" role="button">cancel</i>
          </div>
        </div>

        <div class="mdc-form-field">
          <div class="mdc-checkbox">
            <input type="checkbox" class="mdc-checkbox__native-control" id="toggle-trailing-icon" aria-labelledby="toggle-disabled-label">
            <div class="mdc-checkbox__background">
              <svg class="mdc-checkbox__checkmark" viewBox="0 0 24 24">
                <path class="mdc-checkbox__checkmark-path" fill="none" stroke="white" d="M1.73,12.91 8.1,19.28 22.79,4.59">
              </svg>
              <div class="mdc-checkbox__mixedmark"></div>
            </div>
          </div>
          <label for="toggle-trailing-icon" id="toggle-trailing-icon-label">Require confirmation before removing chip</label>
        </div>
      </section>

      <section class="example">
        <h2>Choice Chips</h2>
        <div class="mdc-chip-set mdc-chip-set--choice">
          <div class="demo-chip mdc-chip" tabindex="0">
            <div class="mdc-chip__text">Extra Small</div>
          </div>
          <div class="demo-chip mdc-chip" tabindex="0">
            <div class="mdc-chip__text">Small</div>
          </div>
          <div class="demo-chip mdc-chip mdc-chip--selected" tabindex="0">
            <div class="mdc-chip__text">Medium</div>
          </div>
          <div class="demo-chip mdc-chip" tabindex="0">
            <div class="mdc-chip__text">Large</div>
          </div>
          <div class="demo-chip mdc-chip" tabindex="0">
            <div class="mdc-chip__text">Extra Large</div>
          </div>
        </div>
      </section>

      <section class="example">
        <h2>Filter Chips</h2>
        <h4>No leading icon</h4>
        <div class="mdc-chip-set mdc-chip-set--filter">
          <div class="demo-chip mdc-chip mdc-chip--selected" tabindex="0">
            <div class="mdc-chip__checkmark" >
              <svg class="mdc-chip__checkmark-svg" viewBox="-2 -3 30 30">
                <path class="mdc-chip__checkmark-path" fill="none" stroke="black" d="M1.73,12.91 8.1,19.28 22.79,4.59"/>
              </svg>
            </div>
            <div class="mdc-chip__text">Tops</div>
          </div>
          <div class="demo-chip mdc-chip mdc-chip--selected" tabindex="0">
            <div class="mdc-chip__checkmark" >
              <svg class="mdc-chip__checkmark-svg" viewBox="-2 -3 30 30">
                <path class="mdc-chip__checkmark-path" fill="none" stroke="black" d="M1.73,12.91 8.1,19.28 22.79,4.59"/>
              </svg>
            </div>
            <div class="mdc-chip__text">Bottoms</div>
          </div>
          <div class="demo-chip mdc-chip" tabindex="0">
            <div class="mdc-chip__checkmark" >
              <svg class="mdc-chip__checkmark-svg" viewBox="-2 -3 30 30">
                <path class="mdc-chip__checkmark-path" fill="none" stroke="black" d="M1.73,12.91 8.1,19.28 22.79,4.59"/>
              </svg>
            </div>
            <div class="mdc-chip__text">Shoes</div>
          </div>
          <div class="demo-chip mdc-chip" tabindex="0">
            <div class="mdc-chip__checkmark" >
              <svg class="mdc-chip__checkmark-svg" viewBox="-2 -3 30 30">
                <path class="mdc-chip__checkmark-path" fill="none" stroke="black" d="M1.73,12.91 8.1,19.28 22.79,4.59"/>
              </svg>
            </div>
            <div class="mdc-chip__text">Accessories</div>
          </div>
        </div>
        <br>
        <h4>With leading icon</h4>
        <div class="mdc-chip-set mdc-chip-set--filter">
          <div class="demo-chip mdc-chip mdc-chip--selected" tabindex="0">
            <i class="material-icons mdc-chip__icon mdc-chip__icon--leading mdc-chip__icon--leading-hidden">face</i>
            <div class="mdc-chip__checkmark" >
              <svg class="mdc-chip__checkmark-svg" viewBox="-2 -3 30 30">
                <path class="mdc-chip__checkmark-path" fill="none" stroke="black" d="M1.73,12.91 8.1,19.28 22.79,4.59"/>
              </svg>
            </div>
            <div class="mdc-chip__text">Alice</div>
          </div>
          <div class="demo-chip mdc-chip" tabindex="0">
            <i class="material-icons mdc-chip__icon mdc-chip__icon--leading">face</i>
            <div class="mdc-chip__checkmark" >
              <svg class="mdc-chip__checkmark-svg" viewBox="-2 -3 30 30">
                <path class="mdc-chip__checkmark-path" fill="none" stroke="black" d="M1.73,12.91 8.1,19.28 22.79,4.59"/>
              </svg>
            </div>
            <div class="mdc-chip__text">Bob</div>
          </div>
          <div class="demo-chip mdc-chip" tabindex="0">
            <i class="material-icons mdc-chip__icon mdc-chip__icon--leading">face</i>
            <div class="mdc-chip__checkmark" >
              <svg class="mdc-chip__checkmark-svg" viewBox="-2 -3 30 30">
                <path class="mdc-chip__checkmark-path" fill="none" stroke="black" d="M1.73,12.91 8.1,19.28 22.79,4.59"/>
              </svg>
            </div>
            <div class="mdc-chip__text">Charlie</div>
          </div>
          <div class="demo-chip mdc-chip" tabindex="0">
            <i class="material-icons mdc-chip__icon mdc-chip__icon--leading">face</i>
            <div class="mdc-chip__checkmark" >
              <svg class="mdc-chip__checkmark-svg" viewBox="-2 -3 30 30">
                <path class="mdc-chip__checkmark-path" fill="none" stroke="black" d="M1.73,12.91 8.1,19.28 22.79,4.59"/>
              </svg>
            </div>
            <div class="mdc-chip__text">David</div>
          </div>
        </div>
      </section>

      <section class="example">
        <h2>Action Chips</h2>
        <div class="mdc-chip-set">
          <div class="demo-chip mdc-chip" tabindex="0">
            <i class="material-icons mdc-chip__icon mdc-chip__icon--leading">wb_sunny</i>
            <div class="mdc-chip__text">Turn on lights</div>
          </div>
          <div class="demo-chip mdc-chip" tabindex="0">
            <i class="material-icons mdc-chip__icon mdc-chip__icon--leading">bookmark</i>
            <div class="mdc-chip__text">Bookmark</div>
          </div>
          <div class="demo-chip mdc-chip" tabindex="0">
            <i class="material-icons mdc-chip__icon mdc-chip__icon--leading">alarm</i>
            <div class="mdc-chip__text">Set alarm</div>
          </div>
          <div class="demo-chip mdc-chip" tabindex="0">
            <i class="material-icons mdc-chip__icon mdc-chip__icon--leading">directions</i>
            <div class="mdc-chip__text">Get directions</div>
          </div>
        </div>
      </section>

      <section class="example">
        <h2>Custom theme</h2>
        <div class="mdc-chip-set">
          <div class="custom-chip-primary demo-chip mdc-chip" tabindex="0">
            <div class="mdc-chip__text">Add to Calendar</div>
          </div>
          <div class="custom-chip-primary demo-chip mdc-chip" tabindex="0">
            <div class="mdc-chip__text">Bookmark</div>
          </div>
          <div class="custom-chip-primary demo-chip mdc-chip" tabindex="0">
            <div class="mdc-chip__text">Set Alarm</div>
          </div>
          <div class="custom-chip-primary demo-chip mdc-chip" tabindex="0">
            <div class="mdc-chip__text">Get Directions</div>
          </div>
        </div>
        <div class="mdc-chip-set">
          <div class="custom-chip-secondary demo-chip mdc-chip" tabindex="0">
            <div class="mdc-chip__text">Add to Calendar</div>
          </div>
          <div class="custom-chip-secondary demo-chip mdc-chip" tabindex="0">
            <div class="mdc-chip__text">Bookmark</div>
          </div>
          <div class="custom-chip-secondary demo-chip mdc-chip" tabindex="0">
            <div class="mdc-chip__text">Set Alarm</div>
          </div>
          <div class="custom-chip-secondary demo-chip mdc-chip" tabindex="0">
            <div class="mdc-chip__text">Get Directions</div>
          </div>
        </div>
      </section>
    </main>

    <script src="/assets/material-components-web.js" async></script>
    <script>
      demoReady(function() {
        var inputChipSetEl = document.getElementById('input-chip-set');
        var chipSets = document.querySelectorAll('.mdc-chip-set:not(#input-chip-set)');
        var input = document.getElementById('input-chip-set-input');
        var inputButton = document.getElementById('input-chip-set-button');
        var deleteButton = document.getElementById('input-chip-set-delete-button');
        var trailingIconToggle = document.getElementById('toggle-trailing-icon');

        [].forEach.call(chipSets, function(chipSet) {
          mdc.chips.MDCChipSet.attachTo(chipSet);
        });
        var inputChipSetComponent = mdc.chips.MDCChipSet.attachTo(inputChipSetEl);

        inputButton.addEventListener('click', addInputChip);
        input.addEventListener('keydown', addInputChip);
        deleteButton.addEventListener('click', deleteLastChip);
        inputChipSetEl.addEventListener('MDCChip:removal', removeChip);
        trailingIconToggle.addEventListener('change', resetInputChipSet);

        function resetInputChipSet() {
          inputChipSetComponent.destroy();
          if (this.checked) {
            inputChipSetComponent = new mdc.chips.MDCChipSet(inputChipSetEl, undefined, function(chipEl) {
              const chip = new mdc.chips.MDCChip(chipEl);
              chip.shouldRemoveOnTrailingIconClick = false;
              return chip;
            });
            inputChipSetEl.addEventListener('MDCChip:trailingIconInteraction', confirmChipRemoval);
          } else {
            inputChipSetComponent = mdc.chips.MDCChipSet.attachTo(inputChipSetEl);
            inputChipSetEl.removeEventListener('MDCChip:trailingIconInteraction', confirmChipRemoval);
          }
        }

        function createChipEl(text, leadingIcon, trailingIcon) {
          const chipTextEl = document.createElement('div');
          chipTextEl.classList.add('mdc-chip__text');
          chipTextEl.appendChild(document.createTextNode(text));

          const chipEl = document.createElement('div');
          chipEl.classList.add('mdc-chip');
          if (leadingIcon) {
            chipEl.appendChild(leadingIcon);
          }
          chipEl.appendChild(chipTextEl);
          if (trailingIcon) {
            chipEl.appendChild(trailingIcon);
          }
          return chipEl;
        }

        function addInputChip(evt) {
          if ((evt.type === 'click' || evt.key === 'Enter' || evt.keyCode === 13) &&
              input.value !== '') {
            var leadingIcon = document.querySelector('.input-leading-icon').cloneNode(true);
            var trailingIcon = document.querySelector('.input-trailing-icon').cloneNode(true);

            var newChipEl = createChipEl(input.value, leadingIcon, trailingIcon);
            inputChipSetEl.appendChild(newChipEl);
            inputChipSetComponent.addChip(newChipEl);

            input.value = '';
          }
        };

        function confirmChipRemoval(evt) {
          if (confirm('Are you sure you want to remove this chip?')) {
            evt.detail.chip.beginExit();
          }
        }

        function removeChip(evt) {
          const root = evt.detail.root;
          root && inputChipSetEl.removeChild(root);
        }

        function deleteLastChip() {
          const lastChipIndex = inputChipSetComponent.chips.length - 1;
          const lastChip = inputChipSetComponent.chips[lastChipIndex];
          lastChip.beginExit();
        };
      });
    </script>
  </body>
</html>
